<template>
	<view class="content">
		<view class="text" @click="yulan(c_data.contract)">
			<image :src="c_data.contract" mode="widthFix"></image>
		</view>
		<view class="scik" v-if="c_data.status == '签署中'">
			<signInput ref="sign" :header="header" :action="action" @signToUrl="signToUrl" bgColor="#ffffff"
				:outSignWidth="792" :outSignHeight="360" :infodata="infodata">
			</signInput>
			<view class="tijiao" @click="tijiao">
				提交
			</view>
		</view>
	</view>
</template>
<script>
	import signInput from "@/shopowner/components/am-sign-input/am-sign-input.vue"
	export default {
		components: {
			signInput
		},
		data() {
			return {
				action: "https://wx.caobenjiankang.com/index.php?i=666&m=longbing_massages_city&s=admin/app/wx/uploadFile&urls=store/apadmin/app/wx/uploadFile", //上传服务器的地址
				header: {
					autograph: ''
				}, //图片上传携带头部信息
				c_data: {},
				infodata: {
					id: 0,
					mobile: '',
					id_number: '',
					signature: '',
					name: ''
				}
			}
		},
		onLoad(op) {
			this.infodata.id = op.id
			this.getData(op.id)
			const au = uni.getStorageSync('autograph')
			this.header.autograph = au
		},
		methods: {
			async getData(id) {
				let data = await this.$api.shopowner.contractDetail({ id: id })
				this.c_data = data
				this.infodata.mobile = data.mobile
				this.infodata.id_number = data.id_number
				this.infodata.name = data.name
			},
			/**
			 * @param {Object} e
			 * 返回的签名地址
			 */
			signToUrl(e) {
				const info = JSON.parse(e.data)
				if (info.code == '200') {
					this.infodata.signature = info.data.attachment_path
				} else {
					uni.showToast({
						title: e.msg,
						icon: 'none'
					})
				}
			},
			async tijiao() {
				const data = await this.$api.shopowner.contractSignature(this.infodata)
				uni.showToast({
					title: data,
					icon: 'none'
				})
			},
			yulan(url) {
				const list = [url]
				uni.previewImage({
					urls: list,
					longPressActions: {
						success: function(data) {
							console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			}
		},
	}
</script>
<style lang="scss">
	.content {
		background: #ffffff;
		padding: 60rpx 30rpx;
		display: flex;
		flex-direction: column;
	}

	.text {
		min-height: 100vh;
		padding-bottom: 400rpx;
	}

	.scik {
		position: sticky;
		bottom: 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-bottom: 58rpx;
		background-color: #ffffff;
	}

	.tijiao {
		width: 100%;
		border-radius: 16rpx;
		height: 80rpx;
		background-color: #1DB481;
		color: #ffffff;
		line-height: 80rpx;
		text-align: center;
		margin-top: 24rpx;
	}
</style>